package com.xuecheng.manage_media.controller;

import com.xuecheng.api.media.MediaControllerApi;
import com.xuecheng.framework.domain.media.response.CheckChunkResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_media.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/media/upload")
public class MediaController implements MediaControllerApi {
    @Autowired
    MediaService mediaService;

    /**
     * @Description: 上传分块注册 进行检查
     * @Param:
     * @return:
     * @Author: Mr.Yuan
     * @Date:
     */
    @PostMapping("/register")
    @Override
    public ResponseResult fileRegister(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {
        return mediaService.fileRegister(fileMd5, fileName, fileSize, mimetype, fileExt);
    }

    /**
     * @Description: 检查块文件是否存在
     * @Param:
     * @return:
     * @Author: Mr.Yuan
     * @Date:
     */
    @PostMapping("/checkchunk")
    @Override
    public CheckChunkResult checkchunk(String fileMd5, Integer chunk, Integer chunkSize) {

        return mediaService.checkchunk(fileMd5, chunk, chunkSize);
    }

    /**
     * @Description: 上传块文件
     * @Param:
     * @return:
     * @Author: Mr.Yuan
     * @Date:
     */
    @PostMapping("/uploadchunk")
    @Override
    public ResponseResult uploadchunk(MultipartFile file, Integer chunk, String fileMd5) {
        return mediaService.uploadchunk(file, chunk, fileMd5);
    }

    /**
     * @Description: 合并分块
     * @Param:
     * @return:
     * @Author: Mr.Yuan
     * @Date:
     */
    @PostMapping("/mergechunks")
    @Override
    public ResponseResult mergechunks(String fileMd5, String fileName, Long fileSize, String mimetype, String fileExt) {
        return mediaService.mergechunks(fileMd5, fileName, fileSize, mimetype, fileExt);
    }
}
